package com.hs.lin.controller;

import com.hs.dto.ResultBean;
import com.hs.lin.pojo.ExceptionHandling;
import com.hs.lin.service.IExceptionHandlingService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Lin GongZi
 * @since 2022-06-13
 */
@RestController
@CrossOrigin
@RequestMapping("/exceptionHandling")
@Api(tags = "异常处理测试")
public class ExceptionHandlingController {

    @Autowired
    private IExceptionHandlingService exceptionHandlingService;

    /**
     * 异常处理信息回显
     * @return
     */
    @GetMapping
    public ResultBean exceptionHandling(String id){
        //查询操作
        return exceptionHandlingService.exceptionHandling(id);
    }

    /**
     * 添加异常处理信息
     * @param exceptionHandling
     * @return
     */
    @PostMapping("/{exceptionNo}")
    public ResultBean addExceptionHandling(@RequestBody ExceptionHandling exceptionHandling ,@PathVariable String exceptionNo){
        return exceptionHandlingService.add(exceptionHandling,exceptionNo);
    }

    /**
     * 查询异常处理信息
     * @return
     */
    @GetMapping("/hand")
    public ResultBean queryExceptionHandling(String id){
        return exceptionHandlingService.find(id);
    }

    /**
     * 导出为excel表格
     * @param currentPage
     * @param pageSize
     * @param resp
     */
    @GetMapping("/excel")
    public void inputExcel(Integer currentPage,Integer pageSize, String exId,String oId,String cId,String exceptionType, HttpServletResponse resp) throws IOException {
        exceptionHandlingService.inputExcel(currentPage,pageSize,exId,oId,cId,exceptionType,resp);
    }
}
